package com.ruoyi.bookbus.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bookbus.domain.BookForumTopic;
import com.ruoyi.bookbus.service.IBookForumTopicService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 论坛主题Controller
 * 
 * @author zsq-cj
 * @date 2025-10-21
 */
@RestController
@RequestMapping("/bookbus/topic")
public class BookForumTopicController extends BaseController
{
    @Autowired
    private IBookForumTopicService bookForumTopicService;

    /**
     * 查询论坛主题列表
     */
    @PreAuthorize("@ss.hasPermi('bookbus:topic:list')")
    @GetMapping("/list")
    public TableDataInfo list(BookForumTopic bookForumTopic)
    {
        startPage();
        List<BookForumTopic> list = bookForumTopicService.selectBookForumTopicList(bookForumTopic);
        return getDataTable(list);
    }

    /**
     * 导出论坛主题列表
     */
    @PreAuthorize("@ss.hasPermi('bookbus:topic:export')")
    @Log(title = "论坛主题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BookForumTopic bookForumTopic)
    {
        List<BookForumTopic> list = bookForumTopicService.selectBookForumTopicList(bookForumTopic);
        ExcelUtil<BookForumTopic> util = new ExcelUtil<BookForumTopic>(BookForumTopic.class);
        util.exportExcel(response, list, "论坛主题数据");
    }

    /**
     * 获取论坛主题详细信息
     */
    @PreAuthorize("@ss.hasPermi('bookbus:topic:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bookForumTopicService.selectBookForumTopicById(id));
    }

    /**
     * 新增论坛主题
     */
    @PreAuthorize("@ss.hasPermi('bookbus:topic:add')")
    @Log(title = "论坛主题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BookForumTopic bookForumTopic)
    {
        return toAjax(bookForumTopicService.insertBookForumTopic(bookForumTopic));
    }

    /**
     * 修改论坛主题
     */
    @PreAuthorize("@ss.hasPermi('bookbus:topic:edit')")
    @Log(title = "论坛主题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BookForumTopic bookForumTopic)
    {
        return toAjax(bookForumTopicService.updateBookForumTopic(bookForumTopic));
    }

    /**
     * 删除论坛主题
     */
    @PreAuthorize("@ss.hasPermi('bookbus:topic:remove')")
    @Log(title = "论坛主题", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bookForumTopicService.deleteBookForumTopicByIds(ids));
    }
}
